package nc.pubimpl.so.pfxx;

import java.util.List;
import nc.bs.pfxx.ISwapContext;
import nc.bs.pfxx.plugin.AbstractPfxxPlugin;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.pfxx.auxiliary.AggxsysregisterVO;
import nc.vo.pfxx.util.PfxxPluginUtils;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pubapp.pattern.pub.PubAppTool;










public abstract class AbstractSOPfxxPlugin
  extends AbstractPfxxPlugin
{
  private List<IRule<AggregatedValueObject>> checkers;
  
  public AbstractSOPfxxPlugin() {}
  
  public List<IRule<AggregatedValueObject>> getCheckers()
  {
    return this.checkers;
  }
  
















  protected Object processBill(Object vo, ISwapContext swapContext, AggxsysregisterVO aggxsysvo)
    throws BusinessException
  {
    AggregatedValueObject resvo = (AggregatedValueObject)vo;
    String vopk = PfxxPluginUtils.queryBillPKBeforeSaveOrUpdate(swapContext.getBilltype(), swapContext.getDocID());
    AggregatedValueObject returnVO = null;
    checkBill(resvo);
    
    if (PubAppTool.isNull(vopk)) {
      resvo.getParentVO().setStatus(2);
      for (CircularlyAccessibleValueObject bvo : resvo.getChildrenVO()) {
        bvo.setStatus(2);
      }
      returnVO = insert(resvo);
    } else {
      returnVO = update(resvo, vopk);
    }
    if(PubAppTool.isNull(vopk)){
	    vopk = returnVO.getParentVO().getPrimaryKey();
	    PfxxPluginUtils.addDocIDVsPKContrast(swapContext.getBilltype(), swapContext.getDocID(), vopk);
    }
    return returnVO.getParentVO().getPrimaryKey();
  }
  






  protected abstract AggregatedValueObject insert(AggregatedValueObject paramAggregatedValueObject) throws BusinessException;
  






  protected abstract AggregatedValueObject update(AggregatedValueObject paramAggregatedValueObject, String paramString) throws BusinessException;
  





  private void checkBill(AggregatedValueObject vo)
  {
    if (getCheckers() != null) {
      for (IRule<AggregatedValueObject> checker : getCheckers()) {
        checker.process(new AggregatedValueObject[] { vo });
      }
    }
  }
}